package com.dingreading.cloud.common.util;

import java.util.Date;
import java.util.concurrent.TimeUnit;

/**
 * 时间相关工具
 */
public class TimeUtil {

    /**
     * 传递的日期是否超过系统日期多少天
     *
     * @param date 传递的日期
     * @param days 超过的天数
     * @return boolean
     */
    public static boolean moreThanDay(Date date, Integer days) {
        // 判断日期超过x天
        long nowTime = System.currentTimeMillis();
        long dateTime = date.getTime();
        long l1 = nowTime - dateTime;
        // x天
        long day = days * 24 * 60 * 60 * 1000L;
        return l1 > day;
    }

    public static boolean moreThanDay2(Date date, Integer days) {
        // 判断日期超过x天
        Date time = DateUtil.getNowDatetime();
        Date dateTime = DateUtil.addDays(date, days);
        return time.getTime() > dateTime.getTime();
    }

    /**
     * 秒转换成时分秒
     */
    public static String convertSecondsToHMS(long seconds) {
        long hours = TimeUnit.SECONDS.toHours(seconds);
        long minutes = TimeUnit.SECONDS.toMinutes(seconds) % 60;
        long remainingSeconds = seconds % 60;

        String time = "";
        if (hours > 0)
            time += hours + "小时";
        if (minutes > 0)
            time += minutes + "分钟";
        if (remainingSeconds > 0)
            time += remainingSeconds + "秒";
        return time;
    }

}
